﻿
Partial Class WebForm_Main_SearchTrainingCourse
    Inherits System.Web.UI.UserControl

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            RaiseEvent Loaded(Me, New EventArgs)
        End If
    End Sub

    Protected Sub gvTrainingCourseInfo_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gvTrainingCourseInfo.PageIndexChanging
        Me.gvTrainingCourseInfo.PageIndex = e.NewPageIndex
        Me.BindGV()
    End Sub
End Class

Partial Class WebForm_Main_SearchTrainingCourse
    Public Sub BindGV()
        Dim sql As New MyStringBuilder
        Dim dat As New clsData

        sql.AppendFormat("SELECT tcg.*, isnull(tr.RegisterCount, 0) RegisterCount, cm_GroupType.Text as GroupTypeText  from TrainingCourseGroup tcg ")
        sql.AppendFormat("inner join CodeMapping cm_GroupType on tcg.GroupType = cm_GroupType.Value and cm_GroupType.TableName = 'TrainingCourseGroup' and cm_GroupType.ColumnName = 'GroupType' ")
        sql.AppendFormat("left join (select GroupID, Count(*) RegisterCount from TrainingRegister group by GroupID) tr on tcg.ID = tr.GroupID ")
        sql.AppendFormat("where getdate() <=tcg.StartDate  ")
        sql.AppendFormat(" Order By tcg.StartDate ")

        Me.gvTrainingCourseInfo.DataSource = dat.GetData(sql)
        Me.gvTrainingCourseInfo.DataBind()
    End Sub

    Public Event Loaded(ByVal source As Object, ByVal e As EventArgs)
End Class